package cc.mrbird.febs.common.converter;

import cc.mrbird.febs.system.domain.TShopTaxInfo;
import com.wuwenze.poi.convert.ReadConverter;
import com.wuwenze.poi.exception.ExcelKitReadConverterException;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class TaxInfoExcelReadConverter implements ReadConverter {
    @Override
    public Object convert(Object o) throws ExcelKitReadConverterException {
        String value = (String) o;

        List<TShopTaxInfo> taxes = new ArrayList<>();
        if(StringUtils.isNotBlank(value)) {
            String[] tasGroupItem = value.contains(",") ? value.split(",") : value.split("，");
            for(String tgi: tasGroupItem) {
                TShopTaxInfo taxTmp = new TShopTaxInfo();
                String[] taxStrTmp = tgi.contains(":") ? tgi.split(":") : tgi.split("：");
                taxTmp.setTaxYear(Integer.valueOf(taxStrTmp[0]));
                taxTmp.setTaxSum(BigDecimal.valueOf(Double.valueOf(taxStrTmp[1])));
                taxes.add(taxTmp);
            }
        }
        return taxes;
    }
}
